﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UltiDrive
{
    public enum StorageServices { SkyDrive, Dropbox, GoogleDrive };

    class Utilities
    {
        public static string ParseSourceForIdentifier(string identifier, Uri source)
        {
            return ParseSourceForIdentifier(identifier, source.ToString());
        }

        public static string ParseSourceForIdentifier(string identifier, string source)
        {
            //looks through the URL to find the specified identifier and returns the value of the identifier
            //i.e. if given string moneymaker = "?source=desktop&view=mobile"
            //method(view, moneymaker) returns mobile
            string result = "";

            if (source.IndexOf(identifier) == -1)
                return null;

            int NextEqualSign = source.IndexOf('=', source.IndexOf(identifier));

            if (source.LastIndexOf('&') > source.IndexOf(identifier))
            {
                int NextAmpersand = source.IndexOf('&', NextEqualSign);
                result = source.Substring(NextEqualSign + 1, NextAmpersand - NextEqualSign - 1);
            }
            else
            {
                result = source.Substring(NextEqualSign + 1, source.Length - NextEqualSign);
            }

            return result;
        }

        public static void RefreshService(StorageServices service)
        {
            if (service == StorageServices.SkyDrive)
            {
                
            }
        }
    }
}
